﻿@model IEnumerable<RepertorySystem.Models.InputStorage>
@Scripts.Render("~/bundles/jquery")
@{
    ViewBag.Title = "Index";
}
<h2>入库单列表</h2>
@*<p>
    @Html.ActionLink("添加新入库单", "Create")
</p>*@

@{
    //获取端口
    IServiceProvider provider = (IServiceProvider)HttpContext.Current;
    HttpWorkerRequest request = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
    var port = HttpContext.Current.Request.Url.Port;

}
<div class="col-lg-3 divfloat">
    <div class="input-group">
        <input id="searchInput" type="text" class="form-control" placeholder="输入书名" />
        <span class="input-group-btn">
            <input id="searchButton" class="btn btn-default" type="button" value="搜索" />
        </span>
    </div><!-- /input-group -->
</div>
<script type="text/javascript">
    $("#searchButton").click(function(){
        var searchContent = $("#searchInput").val();

        if(searchContent == "" ){
            alert("请输入搜索内容");
        }else{
            window.location.href ="http://localhost:"+@port+"/InputStorages/FindOne?book_Name="+searchContent;
        }
    });

</script>

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Book_Id)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Number)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Time)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Price)
        </th>
        <th></th>
    </tr>
   @if (ViewBag.content == null) {
    <tr>未查找到内容！</tr>
   } else {
       foreach (var item in ViewBag.content) {
        <tr>
            <td class="@item.Book_Id">

                @if (@item.Book_Id != null) {

                    <script type="text/javascript">
                        var bookId = @item.Book_Id;
                        $.ajax({
                            url: "http://localhost:"+@port+"/api/Books/"+bookId,
                            type:"get",
                            success: function (result) {
                                $(".@item.Book_Id").text(result.Name);

                                //alert(result.Name);
                            },
                            error: function (msg) {
                                console.log(msg);
                            }

                        });

                    </script>
                }

            </td>
            <td>
                @item.Number
            </td>
            <td>
                @item.Time.ToString("yyyy-MM-dd")
            </td>
            <td>
                @item.Price
            </td>
            <td>
                @*@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |*@
                @*@Html.ActionLink("Details", "Details", new { id = item.ID }) |*@
                <span class="glyphicon glyphicon-trash" style="color: rgb(200, 153, 107); font-size: 15px;">
                    @Html.ActionLink("删除", "Delete", new { id = item.ID })
                </span>            
            </td>

        </tr>

       }
   }
    

</table>
<div id="pagebar">
    <ul class="pagination">
    @for (var i = 0; i < ViewBag.totalPages; i++)
    {

        if (ViewBag.currentPage == (i + 1))
        {
            <li><span class="currentPage">@(i + 1)</span></li>
        }
        else
        {
            //<a class="nextOrPreviousPage" href="javascript:;">@(i + 1)</a>
            var number = i + 1;
            <li>@Html.ActionLink("" + number, "GetNext", new { currentPage = number });</li>
        }
    }
    </ul>
</div>